﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace VIP_Shop
{
    public partial class LoadGRV : Form
    {
        SqlDataAdapter dataAdapter;
        private DataTable Table = new DataTable();
        public LoadGRV()
        {
            InitializeComponent();
        }

        private void LoadGRV_Load(object sender, EventArgs e)
        {
            try
            {
                string strcon = @" Data Source=DARK\SQLEXPRESS;Initial Catalog=banhang;Integrated Security=True";
                dataAdapter =
                    new SqlDataAdapter("select * from mathang", strcon);
                DataSet dataSet = new DataSet();
                dataAdapter.Fill(Table);
                GridView1.DataSource = Table;
            }
            catch (SqlException err)
            {
                MessageBox.Show(err.Message);
                //this.label4.Text = err.Message;
            }        
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            SqlCommandBuilder cb = new SqlCommandBuilder(dataAdapter);
            dataAdapter.Update(Table);
        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            MessageBox.Show("Loi nhap du lieu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            SqlCommandBuilder cb = new SqlCommandBuilder(dataAdapter);
            dataAdapter.Update(Table);
        }

        private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            SqlCommandBuilder cb = new SqlCommandBuilder(dataAdapter);
            dataAdapter.Update(Table);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string mahang = GridView1.CurrentRow.Cells[1].Value.ToString();
            GridView1.Rows.RemoveAt(GridView1.CurrentCell.RowIndex);
            SqlCommandBuilder cb = new SqlCommandBuilder(dataAdapter);
            dataAdapter.Update(Table);
        }

        

    }
}
